package com.service.impl;

import com.dao.LoginDao;
import com.entity.LoginBean;
import com.entity.Manager;
import com.entity.Reader;
import com.entity.User;
import com.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
//1
@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginDao loginDao;
    @Override
    public String login(LoginBean loginBean, HttpServletRequest request) {

        //得到登录账号,密码，类型编号(0=管理员，1=学生，2=教师)
        String uNo=loginBean.getuNo();
        String uPassWord=loginBean.getuPassWord();
        String rTypeNo=loginBean.getrTypeNo();

        //放入map中
        Map<String,String> userMap=new HashMap<>();
        userMap.put("uNo",uNo);
        userMap.put("uPassWord",uPassWord);
        userMap.put("rTypeNo",rTypeNo);

//        System.out.println(userMap);

        //查询验证
        User user=loginDao.doLogin(userMap);
//        System.out.println(user);

        //用户信息放入session中
        HttpSession session=request.getSession();
        session.setAttribute("user",user);
        session.setAttribute("q","qwer");

        if(user!=null){
            return "true";
        }
        return "false";
    }
}
